import org.zjx.task.core.ITaskChain;
import org.zjx.task.core.TaskScheduler;
import org.zjx.task.repository.TaskChainGenerator;
import org.zjx.task.repository.TaskChainRepository;
import org.zjx.task.repository.TaskRepository;
import org.zjx.test.chains.DemoChain;
import org.zjx.test.tasks.DemoTask;
import org.zjx.test.tasks.RetryTask1;
import org.zjx.test.tasks.RetryTask2;

import java.util.List;

public class GeneratorDemo {
    public static void main(String[] args) {

        // 1. 初始化任务/任务链库
        TaskRepository taskRepository = new TaskRepository("org.zjx.test.tasks");
        TaskChainRepository chainRepository = new TaskChainRepository("org.zjx.test.chains");


        // 手动注册任务（如果自动发现失败）
//        taskRepository.registerTask(new DemoTask());
//        taskRepository.registerTask(new RetryTask1());
//        taskRepository.registerTask(new RetryTask2());
//
//        chainRepository.registerChain(new DemoChain());


        // 2. 初始化任务链生成器
        TaskChainGenerator chainGenerator = new TaskChainGenerator(taskRepository, chainRepository);


        // 3. 从配置文件生成任务链
        List<ITaskChain> chains = chainGenerator.generateChainsFromConfigFile("task-chain.txt");

        // 4. 注册任务链
        // 提交任务链进行执行
        TaskScheduler scheduler = new TaskScheduler(4,null);
        try {
            scheduler.addChainToHead(chains);
        } finally {
//            scheduler.shutdown();
        }

    }
}
